<template>
  <!--课程购买-->
  <div>
    <headers></headers>
    <div class="padding88">
      <div class="divider">
        <div class="auto">
          {{lecturer.lecturerName}}导师<span>></span>系列课程列表
        </div>
      </div>
    </div>
    <div class="navs">
      <div class="auto">
        <div class="title">
          {{lecturer.lecturerName}}导师
          <ul class="pull-right">
            <li :class="{active:0===nowIndex}"  @click="tab(0)"><router-link to="#" class="font14">全部</router-link></li>
            <li :class="{active:1===nowIndex}"  @click="tab(1)"><router-link to="##" class="font14">免费</router-link></li>
            <li :class="{active:2===nowIndex}"  @click="tab(2)"><router-link to="##" class="font14">VIP</router-link></li>
            <li :class="{active:3===nowIndex}"  @click="tab(3)"><router-link to="##" class="font14">价格升序</router-link></li>
            <li :class="{active:4===nowIndex}"  @click="tab(4)"><router-link to="##" class="font14">价格降序</router-link></li>
          </ul>
        </div>
      </div>
    </div>
    <div class="auto padding250">
      <div v-if="courses">
        <course v-bind:courses="courses"  v-bind:online="1" v-bind:isVip="isVip"></course>
        <div class="pageout"><Page :total="total" :current="pageNumber" :page-size="size" @on-change="changePage"/></div>
      </div>
      <div v-else>
        <nodata tip="暂时还没有课程哦~"></nodata>
      </div>
    </div>
    <Spin fix v-show="isSpinShow" >
      <div class="loader">
        <Icon type="ios-loading" size=26 class="demo-spin-icon-load"></Icon>
        <div class="font14">加载中...</div>
      </div>
    </Spin>
    <footers></footers>
  </div>
</template>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">
  /* 旋转效果 */
  .demo-spin-icon-load{
    animation: ani-demo-spin 1s linear infinite;
  }
  @keyframes ani-demo-spin {
    from { transform: rotate(0deg);}
    50% { transform: rotate(180deg);}
    to { transform: rotate(360deg);}
  }
  /* 假如内容过长，一屏放不下，滚动条下拉覆盖不全 */
  .ivu-spin-fix {
    position: fixed;
  }

  .divider{
    height: 60px;
    background-color: #2F261E;
    font-size: 14px;
    line-height: 60px;
    text-align: left;
    color: #fff;
    span{
      margin: 0 10px;
    }
    a{
      color: #fff;
      &:hover{
        color: #9C7649;
        font-weight: 700;
      }
    }
  }
  .navs{
    background-color: #fff;
  }
  .title{
    font-size: 20px;
    color: #000;
    padding: 15px;
    text-align: left;
    li{
      display: inline-block;
      margin-right: 30px;
      a{
        padding: 15px 5px;
        font-size: 14px;
        color: #333;
      }
    }
    li.active {
      a{
        font-weight: 700;
        color: #957960;
        border-bottom: 3px solid #957960;
      }
    }
    li:last-child{
      margin-right: 0;
    }
  }
</style>
<script type="text/ecmascript-6">
  import course from '../template/course'
  import headers from '../template/header'
  import footers from '../template/footer'
  import nodata from '../template/null'
  import {centreInfoWeb, lecturerCourseWeb} from '../../http'
  import {getStore} from "../../storage";
  export default {
    name: 'list',
    props: {},
    data() {
      return {
        nowIndex:0,       //课程类别选择
        courses:'',       //课程
        total:0,          //总数
        size:16,          //每页个数
        pageNumber:1,     //页数
        sortOrder:'S0',   //排序方式
        lecturerId:this.$route.query.lecturerId,    //讲师Id
        lecturer:'',      //讲师信息
        isVip:0,          //是否Vip免费
        isSpinShow:false,
      };
    },
    methods: {
      //获取讲师课程
      getLecturerCourse(){
        lecturerCourseWeb({lecturerId:this.lecturerId,sortOrder:this.sortOrder,pageNumber:this.pageNumber,pageSize:this.size}).then(res => {
          this.isSpinShow = false;
          if(res.code === 200) {
            this.courses = res.data.lists.rows;
            this.total = res.data.lists.total;
            this.lecturer = res.data.lecturer;
            this.isVip = res.data.isVip;
          }else {
            this.$Notice.warning({
              title: '系统错误',
              desc: '请刷新页面',
              duration: 3,
            });
          }
        }).catch()
      },
      //排序类型切换
      tab(index){
        this.nowIndex = index;
        this.sortOrder = 'S' + index;
        this.pageNumber = 1;
        //获取讲师课程
        if(this.isSpinShow === false){
          this.isSpinShow = true;
          if (getStore('token') !== null && getStore('token') !== undefined && getStore('token') !== '') {
            //获取用户信息
            centreInfoWeb().then(res => {
                if (res.code === 200) {
                    this.getLecturerCourse();
                  } else {
                  this.getLecturerCourse();
                }
            }).catch()
          } else {
            this.getLecturerCourse();
          }
        }
      },
      //页码切换
      changePage(pageNumber){
        this.pageNumber = pageNumber;
        //获取讲师课程
        if(this.isSpinShow === false) {
          this.isSpinShow = true;
          if (getStore('token') !== null && getStore('token') !== undefined && getStore('token') !== '') {
            //获取用户信息
            centreInfoWeb().then(res => {
              if (res.code === 200) {
                this.getLecturerCourse();
              } else {
                this.getLecturerCourse();
              }
            }).catch()
          } else {
            this.getLecturerCourse();
          }
        }
      },
    },
    created() {
      //获取讲师课程
      if(this.isSpinShow === false) {
        this.isSpinShow = true;
        if (getStore('token') !== null && getStore('token') !== undefined && getStore('token') !== '') {
          //获取用户信息
          centreInfoWeb().then(res => {
            if (res.code === 200) {
              this.getLecturerCourse();
            } else {
              this.getLecturerCourse();
            }
          }).catch()
        } else {
          this.getLecturerCourse();
        }
      }
    },
    components: {
      headers,
      footers,
      course,
      nodata
    }
  }
</script>
